import tkinter as tk
from tkinter import ttk
from tkinter import simpledialog
window=tk.Tk()
window.title("To Do List")
window.geometry("800x600")
columns=["To_Do","In Progress","Done"]
frames={}
for col in columns:
    frame=tk.Frame(window,relief=tk.RAISED,borderwidth=1)
    frame.pack(side=tk.LEFT,fill=tk.BOTH,expand=True)
    frames[col]=frame
    label=tk.Label(frame,text=col,bg='lightblue',font=('Arial',12,'bold'))
    label.pack(fill=tk.X)

def create_card(frame):
    card_frame=tk.Frame(frame,relief=tk.RAISED,borderwidth=1,padx=10,pady=10)
    card_frame.pack(fill=tk.X,pady=5)
    task_name=simpledialog.askstring("Enter task name","Please enter task name")
    if not task_name:
        return
    priority=simpledialog.askstring("Enter priority","Please enter priority")
    if not priority:
        return
    due_data=simpledialog.askstring("Enter due data","Please enter due data")
    if not due_data:
        return
    task_label=tk.Label(card_frame,text=f"Task:{task_name}",anchor='w')
    task_label.pack(fill=tk.X)
    priority_label=tk.Label(card_frame,text=f"Priority:{priority}",anchor='w')
    priority_label.pack(fill=tk.X)
    due_data_label=tk.Label(card_frame,text=f"Due data:{due_data}",anchor='w')
    due_data_label.pack(fill=tk.X)
    delete_button=tk.Button(card_frame,text="delete",command=lambda:delete_card(card_frame))
    delete_button.pack(anchor='s')
    edit_button = tk.Button(card_frame, text="edit", command=lambda:edit_task(task_name,card_frame))
    edit_button.pack(anchor='s')
def delete_card(card_frame):
    card_frame.destroy()
def edit_task(task_name, card_frame):
    
    new_task_name = simpledialog.askstring("Edit task name", f"Current task: {task_name}\nPlease enter new task name")
    if new_task_name:
        
        for widget in card_frame.winfo_children():
            if isinstance(widget, tk.Label) and widget.cget('text').startswith("Task:"):
                widget.config(text=f"Task: {new_task_name}")

button=tk.Button(window,text="create",command=lambda: create_card(frames["To_Do"]))
button.pack()
window.mainloop()